
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    currentTab: 0,
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    this.setData({
      currentTab: 0
    })
    getUserOrders(that, 0)
    wx.getSystemInfo({//获取滑块的高宽
      success: function (res) {
        that.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight,
          imageUrl: app.globalData.imageUrl
        });
      }
    });
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  swichNav: function (e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
      getUserOrders(that, e.target.dataset.current);
    }
  },
  calling: function (e) {
    console.log(e)
    wx.makePhoneCall({
      phoneNumber: '' + e.target.id,
    })
  }
  ,
  cancelOrder: function (e) {
    var that = this;
    wx.showModal({
      title: '提示',
      content: '是否取消订单',
      success: function (res) {
        if (res.confirm) {
          cancelOrder(that, e.target.id)
        }
      }
    })
  }
  ,
  delivery:function(e){
    wx.navigateTo({
      url: '../../pages/delivery/delivery?id=' + e.target.id,
    })

  }
})

function getUserOrders(that, _id) {
  var flag = '';
  if (_id == 0) {
    flag = 'delivery'
  } else if (_id == 1) {
    flag = 'shipped'
  } else if (_id == 2) {
    flag = 'completed'
  }
  wx.request({
    url: app.globalData.allUrl + "/orderr/shop_order",
    data: {
      class: flag,
      shop_id: wx.getStorageSync('shopid')
    },
    header: { 'content-type': "application/x-www-form-urlencoded" },
    method: 'POST',
    success: function (res) {
      console.log(res.data)
      if (res.data.lenth!=0){
        that.setData({
          orders: res.data
        })
      }
     
    }
  })
}
